<template>
  <div class="customNav">
    <image class="navBg" src="@/static/bg.png" alt="" v-if="isBg"></image>
    <div :style="navBarStyle" style="margin-bottom: 40rpx;" v-if="isHeight"></div>
    <div class="nav" :style="navBarStyle">
      <view class="left">
        <u-icon name="arrow-left" :color="iconColor" size="36rpx" bold @click="goBack" v-if="isBack"></u-icon>
        <slot name="left"></slot>
      </view>
      <view class="title">{{ title }}</view>
    </div>
  </div>
</template>
<script setup>
import { ref, onBeforeMount } from 'vue'
import uIcon from "@/uni_modules/uview-plus/components/u-icon/u-icon.vue";
defineProps({
  isHeight: {
    type: Boolean,
    default: true
  },
  isBg: {
    type: Boolean,
    default: true
  },
  iconColor: {
    type: String,
    default: "#00000"
  },
  isBack: Boolean,
  title: String
})
const navBarStyle = ref({
  height: "44px",
  paddingTop: "0px"
})
function goBack () {
  uni.navigateBack({
    delta: 1
  })
}
onBeforeMount(() => {
  uni.getSystemInfo({
    success: (res) => {
      const statusBarHeight = res.statusBarHeight || 0;
      // 计算导航栏高度
      const navBarHeight = statusBarHeight + 44;
      // 设置导航栏样式
      navBarStyle.value = {
        height: `${navBarHeight}px`,
        paddingTop: `${statusBarHeight}rpx`
      };
    }
  });
})
</script>
<style lang="scss" scoped>
.customNav {
  text-align: center;

  .navBg {
    width: 100%;
    height: 328rpx;
    position: absolute;
    left: 0;
    top: 0;
  }

  .nav {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;

    .left {
      position: absolute;
      left: 24rpx;
      display: flex;
      align-items: center;

      image {
        width: 80rpx;
        height: 80rpx;
      }
    }

    .title {
      font-weight: 800;
      font-size: 36rpx;
      color: #222222;
    }
  }

}
</style>